<?php $dt2['user']=cache_get_user($data['user_upload']);

 ?>
<div class="wrapMain">
	<div id="row">


		    <div class="col-md-8"> 
        <ul class="breadcrumb" style="background-color:#fff">
        	<li  itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb" ><a href="<?php echo HOME ?>" itemprop="url"> <span itemprop="title"><i class="fa fa-home"></i> Home</span></a></li>
            <li itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb" ><a href="<?php echo HOME ?>truyen" itemprop="url"><span itemprop="title">Truyện</span></a></li>
             <li itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb" ><?php echo $data['theloai2']['2']; ?></li>
             
        </ul>
    
        <!-- START TRUYEN DE CU -->
        <div class="panel panel-default">

  		<div class="panel-body">
  			
            <div class="row" itemscope itemtype="http://schema.org/Book">
             
            		<div class="col-md-3 col-sm-3 col-xs-12" id="truyen-detail-wrapper">
                    	<div class="item_truyen_box" style="text-align:center">
                        		   <?php if($_SESSION['mobile']!=0){?>
                                    <a itemprop="url" href="<?php echo url(); ?>">
                                       <h1 class="name" itemprop='name'><span style="line-height:30px"><?php echo $data['ten'] ?></span></h1>
									</a>
									<?php }?>
                                <div class="img">
                                	<img itemprop='image' src="<?php echo TRUYEN_IMAGE_LOCAL.$data['hinhanh'] ?>" class="img-rounded" />
                                </div>
                                
                                
                                <div id="wrap-rating" class="rating" xmlns:v="http://rdf.data-vocabulary.org/#" typeof="v:Review-aggregate">
                                	<h3 style="font-size: 12px; line-height: 18px;" property="v:itemreviewed"><?php echo $data['ten'] ?></h3>
                                	<div id="truyen-rating" style="margin: 0px auto;" class="basic" data-average="<?= $data['rate_average']; ?>" data-id="1"></div>
                                	
					   				<span rel="v:rating">
						   				<p id="rating-point" typeof="v:Rating">
						   					<span property="v:average"><?= $data['rate_average']; ?></span> / 
	         								<span property="v:best">5</span> 
	         								<p><span property="v:count"><?= $data['rate_count'] ?></span> lượt đánh giá</p>
	         							</p>
	         							
	         						</span>
         							<p style="display: none; margin-top: 3px;" id="rate_message"></p>
         							
         							
					   				
                                </div>
								<!-- JS to add -->
								<script type="text/javascript">
								  $(document).ready(function(){
									rateDisable = false;
									if($.cookie('rtruyen_<?php echo $data['id']; ?>') == '1'){
					
										rateDisable = true;
									}
									  
									$(".basic").jRating({
										bigStarsPath : '<?php echo HOME ?>public/images/stars.png', // path of the icon stars.png
										smallStarsPath : '<?php echo HOME ?>public/images/small.png', // path of the icon small.png
										length : 5,
										decimalLength : 1,
										isDisabled: rateDisable,
										step: true,
										nbRates : 3,
										rateMax : 5,
										showRateInfo:false,
										phpPath : '<?= HOME; ?>index.php?module=ajax&act=ajax&rating=1&act=truyen&id=<?= $data['id']; ?>',
										
										onSuccess : function(data){
											
											if(data){
												if(data.type == 'success'){
													classMsgRating = 'rate_success';
													$.cookie('rtruyen_<?php echo $data['id']; ?>', '1', { expires: 30 });
												}else if(data.type == 'error'){
													classMsgRating = 'rate_error';
												}
												
												$('#rate_message').html('<p class="'+classMsgRating+'">'+data.message+'</p>');
												$('#rate_message').slideDown('normal').delay(3000).slideUp('normal');
											}
											
										  },

										
									});
								  });
								</script>
                                
                                
                                <div class="btn-group-vertical" >
         <?php
			if($data['chuong_list']){?>
        <a class="btn btn-info btn-sm" role="button" href="<?php echo $data['chuongmoinhat_url']?>">Đọc Chương Mới Nhất <i class="fa fa-long-arrow-right"></i> </a>
        <a class="btn btn-info btn-sm" role="button" href="<?php echo $data['chuongbatdau_url']?>">Đọc Từ Đầu <i class="fa fa-thumbs-up"></i> </a>
        	<?php } ?>
        <a class="btn btn-info btn-sm follow-story" role="button">Theo Dõi Truyện  Này <i class="fa fa-bookmark"></i> </a>	
       
        
        </div>
                              	
                        </div><!-- End item_truyen_box -->
                    </div> <!-- End of col-md-3 -->
                      
<div class="col-md-9 col-sm-9 col-xs-12" id="truyen-detail-wrapper">
                     <?php if($_SESSION['mobile']==0){?>   <a itemprop="url" href="<?php echo url(); ?>"><h1 class="name" itemprop='name'><?php echo $data['ten'] ?></h1></a><?php }?>
                    <div class="item_truyen_detail">                   

<ul class="nav nav-tabs" id="truyen_detail">
  <li class="active"><a href="#truyen_thongtin" data-toggle="tab" >Thông Tin</a></li>
  <li><a href="#truyen_noidung" data-toggle="tab">Giới Thiệu</a></li>


</ul>
<div style="height:5px"></div>
<div class="tab-content truyen_thongtin_tab">
  <div class="tab-pane fade in active" id="truyen_thongtin">
  <table class="table" id="truyen_detail_metadata">

                    		<tr>
<td class="author" width="80" style="padding: 5px;">Tác giả:</td>
                    			<td class="author" style="padding: 5px;"><span><a href="<?php echo url_truyen_tacgia($data['tacgia']) ?>" itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name"><?php echo $data['tacgia']?></span></a></span></td>                    		</tr>
                    		<tr>
                    			<td class="theloai">Thể Loại:</td>
                    			<td class="theloai" id="metadata-theloai"><?php echo $data['theloai2']['1']; ?></td>
                    		</tr>
                    		<tr>
                    			<td class="tinhtrang" >Tình Trạng:</td>
                    			<td class="tinhtrang"><span><?php echo $data['tinhtrang-text']; ?></span></td>
                    		</tr>
                            <tr>
<td class="tinhtrang" style="padding: 4px;">Nguồn</td>
                    			<td class="nguon"><div itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><span itemprop="name"><?php if($data['nguon']!=''){ echo $data['nguon'];}else{ echo "Đang cập nhật ...";} ?></span></div></td>                    		</tr>
                    		<tr>
                    			<td class="view" >Lượt Xem:</td>
                    			<td class="view"><span class="badge" style="padding-left: 5px;"><?php echo $data['views']; ?></span></td>
                    		</tr>
                    			<tr>
                    			<td class="view" >Số Chương:</td>
                    			<td class="sochuong" style="padding: 1px 5px;"><span class="badge"><?php echo $data['sochuong']; ?></span></td>
                    		</tr>
                            <tr>
                    			<td class="tukhoa" > Từ Khóa:</td>
                    			<td class="tukhoa"><?php  echo $data['tag']?></td>
                    		</tr>
                    		<tr>
<td class="stat_info" >Đăng bởi:</td>
                    			<td class="stat_info"><span class="author" style="padding-left: 0px;"><?php echo $dt2['user']['show']; ?></span>  &nbsp;&nbsp;&nbsp;<span class="time"><meta itemprop="datePublished" content="<?php echo $data['time_upload']; ?>"><?php echo time_ago($data['time_upload']); ?></span></td>                    		</tr>
                    		<tr>
                    			<td class="stat_info2" >Mới Nhất :</td>
                    			<td class="stat_info2">
                    				<span>
                    					<a href="<?php echo $data['chuongmoinhat_url'] ?>"><?php echo $data['chuongmoinhat']; ?></a>
                    				</span>
                    				</td>
                    		</tr>
                                        <tr>
                                        <?php if($_SESSION['mobile']==0){?>
                    			<td class="stat_info2" >Like Truyện :</td>
                    			<td class="stat_info2">
                                <span style="color:#16a085; font-weight:bold">Hãy Like Google+ và Facebook  truyện này để ủng hộ Mong.vn và giúp truyện ra nhanh hơn</span>
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_google_plusone" g:plusone:size="medium"></a>

</div>
<script type="text/javascript">var addthis_config = {"data_track_addressbar":false};</script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-52206d695b0bc883"></script>
<!-- AddThis Button END -->
<div class="fb-like" data-href="<?php echo url(); ?>" data-layout="standard" data-action="like" data-show-faces="false" data-share="true"></div>
                    				</td>
                    		</tr>
                             <?php }?>
                    	</table>
               
  </div>
  <div class="tab-pane fade" id="truyen_noidung"> 
   					 <div class="noidung" itemprop='description'>
    					 <?php 
              		if($data['noidung']==''){
							$content_show = $data['gioithieu'];
							
						}else{
							$content_show = $data['noidung'];
						}
						echo "<h2 style='font-size:12px'>Bạn đang <strong>đọc truyện ".$data['ten']."</strong> trên website <strong>đọc truyện online</strong></h2>";
						echo $content_show;
							echo "<br/>";
						echo "<div style='font-size:11px'>Bạn đang <strong>đọc truyện ".$data['ten']."</strong> trên website  <a href='".HOME."' ><strong>đọc truyện online</a></strong>. Bạn có thể truy cập website bằng thiết bị di động như iphone,android,windown phone để  đọc truyện nhanh hơn. Hiện tại chúng tôi đang cập nhật tính năng download truyện ".$data['ten']." full pdf và prc. Hi vọng sẽ sớm ra mắt bạn đọc.</div>";
						?>
                         
                         </div>
       </div>
  

</div>



<script>
$('#truyen_detail').click(function (e) {
	
	 
  	e.preventDefault();
  	
  	if($(this).find('.active').find('a').attr('href') != '#truyen_noidung'){
  	  	
	  	if($('.noidung').height() > 150){
			$('.noidung').css('height', '140').css('overflow', 'hidden');
			$('.truyen_thongtin_tab').append('<p id="threedots" style="text-align:center; font-size: 15px;">...</p><p class="viewmore extend">Xem thêm</p>');
			
		}
  }else{
	$('#threedots').remove();
	$('.viewmore').remove();
	$('.noidung').css('height', '');
  }
		  
  	$(this).tab('show');
  
});

$('.item_truyen_detail .viewmore').live('click', function(e){
	if($(this).hasClass('shorten')){
		$('.noidung').css('height', '140').css('overflow', 'hidden');
		$(this).addClass('extend');
		$(this).html('Xem thêm');
		$(this).removeClass('shorten');
		$('#threedots').html('...');
		window.scroll(0,findPos(document.getElementById("truyen_detail")) - 50);
		
	}else{
		$('.noidung').css('height', 'auto');
		$(this).addClass('shorten');
		$(this).html('Rút gọn');
		$(this).removeClass('extend');
		$('#threedots').html('');
	}
});
</script>
    </div><!-- End item_truyen_box -->
                    </div> <!-- End of col-md-9 -->
                   
                    <div  class="clearfix"></div>
                   
  <!-- Adsense -->
  
  
 
 <?php if($_SESSION['mobile']!=0){ ?>
  <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Mobile 320x100 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:320px;height:100px"
     data-ad-client="ca-pub-6643486112344004"
     data-ad-slot="1902269279"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Mobile 320x100 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:320px;height:100px"
     data-ad-client="ca-pub-6643486112344004"
     data-ad-slot="1902269279"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
 <?php } ?> 
  <!--End of adsense -->
  
  
  
  <!-- Start footable -->
           
               
                 <link rel="stylesheet" type="text/css" href="public/exts/footable/css/footable.core.min.css"/>
             	<script type="text/javascript" src="public/exts/paging/js/jquery.jqpagination.min.js"></script>
                <?php $page=ceil($data['sochuong']/30);?>	
				
  			<?php
			if(isset($_SESSION['user'])){
			$db=new db;
			$db->connect();
			$db->query(' select * from truyen_history where truyen_id='.intval($_GET['id']).' and username="'.$_SESSION['user']['username'].'"');
					if($db->num_rows()>0){
						$his=$db->fetchOne();
					 ?>
							<div class="alert alert-warning">
						   <strong>Chương Theo Dõi </strong>  <span class="pull-right"> <a href="<?php echo $his['url']; ?>"><?php echo $his['ten']; ?> </a>-<span style="font-size:11px"><?php echo time_ago($his['ngay']); ?></span></span>
							</div>
					<?php
					}
			}?>
        <Br/>
                
            <?php if($data['sochuong']>0){ ?>    
           <div class="row" style="background-color:#fafafa; padding:4px; margin:5px; border-radius:2px" >
                <div class="col-md-6"><span style="line-height: 28px;">Chọn nhanh: </span>    <span class="badge" style=" line-height:20px; border-radius: 2px; background: #359e9d;"> <input type="text" class="curchuong" style="color:#000; text-align: center;width:35px; border:none; border-radius:2px" value="??" id="curchuong"><?php echo "&nbsp;/&nbsp;".$data['sochuong'];?></span>  <a  class="btn btn-warning btn-sm fchuong">Go <i class="fa fa-angle-double-right"></i> </a>
             
                </div>
                <div class="col-md-6">
                  <div class="nouislider" style="margin-top: 7px;"></div>
                 
                
                </div>
            </div>
          
          <script>
		  $(function(){
			
			
        	$('.nouislider').noUiSlider({
					 range: [0,<?php echo $data['sochuong']; ?>]
					,start: 0
					,step: 1
					,handles: 1
					,serialization: {
						resolution: 1,
						to: [ $(".curchuong"), 'val' ]
					}
				});
				
		$('.fchuong').live('click', function(e){
			e.preventDefault();
			$.ajax({
					url : "index.php",
					type : 'POST',
				
					data : {
						module: 'truyen', 
						act :'fchuong', 
						thutu : $('#curchuong').val(),
						alias:'<?php echo $data['alias'];?>',
						truyen: <?php echo intval($_GET['id']) ?>
					
					},
					
					success : function(data){
						if($.trim(data)!='no_result'){
						location.href=data;
						}else{
							alert('Chương Không tồn tại, xin vui lòng kiểm tra lại');
						}
							
				
					}
				});
			
			
		});
		//Fchuong click
		  })
		  </script>
          <?php }?>
                <div id="wrap_chuong_table">
              	<div id="chuong_table">
                 <table id="table_data" class="footable table  table-striped">
	<thead>
		<tr>
			<th>Danh Sách Chương</th>
		
			
</tr>
	</thead>

	<tbody>
    	<?php
			if($data['chuong_list']){

					foreach($data['chuong_list'] as $row){
				 ?>
						  <tr>
					<td><a href="<?php echo url_truyen_chuong($row['id'],$row['alias'],$data['alias']) ?>" title="<?php echo2($data['ten']." ".$row['ten']) ?>"> <?php echo $row['ten'] ?></a></td>
						
				
				  </tr>
						 <?php }
			}else{?>
            		<tr>
					<td colspan="4"><h1 class="text-center">Chúng tôi đang cập nhật</h1></td>
					
				
				  </tr>
          	<?php }?>
          </tbody>
        
          </table>
          </div> <!-- End table chuong -->
          </div><!-- end wrap_chuong_table -->
            <?php
			if($data['chuong_list']){?>
                 <div style="width:300px; margin:auto">
                 <div class="pagination">
                <a href="#" class="first" data-action="first">&laquo;</a>
                <a href="#" class="previous" data-action="previous">&lsaquo;</a>
                <input type="text" readonly="readonly" data-max-page="<?php echo $page ?>" data-current-page="<?php if(!isset($_GET['page'])){ echo "1";}else{ echo intval($_GET['page']);} ?>" />
                <a href="#" class="next" data-action="next">&rsaquo;</a>
                <a href="#" class="last" data-action="last">&raquo;</a>
				</div>
             	 </div>
            <?php }?>  
         
   <div class="clearfix"></div>   
   <?php if($page>1){    ?>
  <div class="chuong_page" style="color:#999"><i class="fa fa-tags"></i> Trang  : <?php for($k=1; $k<=$page;$k++){ echo " <a href='".url_truyen($data['id'],$data['alias'])."/$k'>$k</a>," ;}?></div>  
  <?php }?>    
  
  <?php if($_SESSION['mobile']==0){?>
  <Br/>
 
  <div class="truyen_tags">
  	<i class="fa fa-tags"></i> Từ Khóa :<?php echo $data['gtags']; ?>
  </div> 
  <?php }?>
                
            </div> <!-- End of row -->
  <script>
                $('.pagination').jqPagination({
					paged: function(page) {
						$('#wrap_chuong_table').append('<div class="loading" id="mainLoading"><div id="loadMoreItems" class="normalLoadBtn"><img width="20" src="public/images/loading.gif" alt="loading" /> Loading </div><div class="clr"></div></div>');
						$('#wrap_chuong_table').css('opacity', 0.4);
						$('#mainLoading').css('display', 'block').center();
						//Remove dom hien tai de nhe hơn
					$('#table_data').remove();
						// Make ajax request with page --
						
			$.ajax({
	    		url : "index.php",
	    		type : 'POST',
	    	//exit();
	    		data : {
		    		module: 'truyen', 
	    			act :'pagination',
					alias:'<?php echo $data['alias'] ?>' ,
	    			page : page,
					truyen: <?php echo intval($_GET['id']) ?>
				
	    		},
	    		
	    		success : function(data){
					
					$('#chuong_table').html(data);
	    			$('#mainLoading').remove();
	    			$('#wrap_chuong_table').css('opacity', 1);
	    	
	    		}
	    	});


						//End of make ajax request 
					}
					});
                </script>
    
                        
  
  		</div> <!-- End of panel body -->
		</div> <!-- End of panel -->

        <!-- End truyen de cu -->
        <div class="panel panel-default">
 		 <div class="panel-heading">
         		<ul class="mn_nav">
                 <li><span class="head">Thảo Luận</span></li>
            
             
              
            </ul>
            <div class="clearfix"></div>
         </div>
  		<div class="panel-body">
        
                                 <script>
			window.fbAsyncInit = function() {
 FB.init({appId: '<?php echo FB_ID;?>', status: true, cookie: true, xfbml: true});

     FB.Event.subscribe('comment.create', function(response) {
          var commentQuery = FB.Data.query('SELECT fromid, text FROM comment WHERE post_fbid=\'' + response.commentID + '\' AND object_id IN (SELECT comments_fbid FROM link_stat WHERE url=\'' + response.href + '\')');
      var user = FB.Data.query(
       "select name, id, url, pic_square from profile where id in"
     + "(select fromid from {0})", commentQuery);
 
  FB.Data.waitOn([commentQuery,user], function () {
   ct = commentQuery.value[0].text;
   u = user.value[0].name;
   td='<?php echo2($data['ten']) ?>';
   url='<?php echo url() ?>';
   m='truyen';
   ip='<?php echo get_ip(); ?>';
   id='<?php echo $_GET['id'] ?>';
	// Query get user info with fromid
	//Send data to server using ajax ------ KAKAKAKAKAKA
			 var   values='comment_user='+u+'&comment_tieude='+td+'&comment_url='+url+'&comment_type='+m+'&ip='+ip+'&comment_id='+id+
    '&comment_content='+ct+'&module=user&act=ajax&add_comment';
	
  	$.ajax({
      url: "index.php",
      type: "post",
      data: values,
      success: function(data){
          },
   
    }); 
	
    // Use your preferred way to inform the server to save comment
     });
 });         
 };
 
 </script>  
  			<!-- Truyen moi content -->
             <style>.fb_iframe_widget,
.fb_iframe_widget span,
.fb_iframe_widget iframe[style]  {width: 100% !important;}</style>
<div class="fb-comments" data-href="<?php echo url();?>" data-numposts="5" data-colorscheme="light"></div>
            <!-- End truyen moi content -->	
         
  
  		</div> <!-- End of panel body -->
		</div> <!-- End of panel -->

      
        
        


</div> <!-- COL MD 9 -->
  
                    <div class="col-md-4">
                    <?php if($_SESSION['mobile']==0){?>
<div style="text-align:center"><input type="hidden" name="optionvalue" id="menu-search-box" class="input-medium" data-placeholder="Nhập Tên Truyện ..."   /></div><Br/>
	<?php }?>
                     	<?php  render_user_box($dt2); ?><br/>
  						<?php truyen_render_theloai(); ?>
                        <div style="width:335px; margin:auto">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ADSENSE MONG -HOME -->
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-6643486112344004"
     data-ad-slot="6332468874"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

</div>
     	<!-- START Render TRUYEN View -->	<?php truyen_render_view(); ?>	
 <!-- START RENDER video comment --> <?php render_pick(); ?> <!-- End RENDER video comment --> 
<!-- START RENDER video Xem Nhieu -->     <?php	truyen_render_right_comment(); ?>   <!-- end video xem nhieu -->


		



					</div> <!-- End col-md-3 right -->




	
	</div><!-- end row -->
</div><!-- end wrapMain -->
<div class="clearfix"></div>

<script type="text/javascript">
	$(document).ready(function(){
		$('.follow-story').live('click',function(e){
			e.preventDefault();
			username = '<?= $_SESSION['user']['username']; ?>';
			if(!username){
				window.location.href = '<?= LOGIN ?>';
				return;
			}
			truyen_id = '<?= $data['id']; ?>';
			username = '<?= $_SESSION['user']['username']; ?>';

			url = '<?php echo url(); ?>';

			$.ajax({
				url: 'index.php?module=user&act=ajax&follow_story=1',
				type: 'POST',
				data: {truyen_id: truyen_id, username: username, url: url},
				success: function(data){
					if(data) newData = $.parseJSON(data);
					if(newData.error){
						popupMessage('Lỗi', [newData.error], 'alert-danger');
					}else if(newData.message){
						popupMessage('Thành công', [newData.message], 'alert-success');
					}
				},
			});
		});

		

		

		$('.pagination a').live('click', function(e){
			
			$('#wrap_chuong_table').append('<div class="loading" id="mainLoading"><div id="loadMoreItems" class="normalLoadBtn"><img width="20" src="public/images/loading.gif" alt="loading" /> Loading </div><div class="clr"></div></div>');
			window.scroll(0,findPos(document.getElementById("chuong_table")) - 50);
		});
	});
</script>